# Maintainer: Renato Silva <br.renatosilva@gmail.com>

_realname=xmlstarlet
pkgdesc="Command-line XML toolkit"
pkgver=r678.9a470e3
pkgrel=2
arch=('any')
license=('MIT')
url="https://xmlstar.sourceforge.io/"
pkgbase=mingw-w64-${_realname}-git
pkgname=(${MINGW_PACKAGE_PREFIX}-${_realname}-git)
provides=(${MINGW_PACKAGE_PREFIX}-${_realname})
conflicts=(${MINGW_PACKAGE_PREFIX}-${_realname})
sha256sums=('SKIP')
source=(${_realname}::"git+https://git.code.sf.net/p/xmlstar/code")
depends=(${MINGW_PACKAGE_PREFIX}-libxml2
         ${MINGW_PACKAGE_PREFIX}-libxslt)
makedepends=(${MINGW_PACKAGE_PREFIX}-gcc ${MINGW_PACKAGE_PREFIX}-libiconv git)

prepare() {
  cd "${srcdir}/${_realname}"
  autoreconf -sif
}

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" $(git rev-list --count HEAD) $(git rev-parse --short HEAD)
}

build() {
  cd "${srcdir}/${_realname}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-libxml-prefix=${MINGW_PREFIX} \
    --with-libxslt-prefix=${MINGW_PREFIX} \
    --with-libiconv-prefix=${MINGW_PREFIX}
    # --enable-static-libs  # To link with libxml/libxslt statically

  make
}

package() {
  cd "${srcdir}/${_realname}"
  make DESTDIR="${pkgdir}" install
  local license_dir="${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  mkdir -p "${license_dir}"
  cp -v Copyright "${license_dir}/Copyright"
  mv -v "${pkgdir}${MINGW_PREFIX}/bin/xml.exe" "${pkgdir}${MINGW_PREFIX}/bin/xmlstarlet.exe"
}
